
import json
import os
import re
import time
from typing import List


def executepotro(proto_name, model):
    proto_path2 = '--proto_path =./psl-be-protocol/room '
    proto_path1 = '--proto_path =./psl-be-protocol/partystar '
    proto_path3 = '--proto_path =./psl-be-protocol/database '

    # dart_out = ' --objc_out=./PSNetworkSet/' + model + '/Classes/protocol/generated '
    # print(dart_out)
    # command = 'protoc ' + proto_path1 + proto_path2 + proto_path3 + dart_out + proto_name
    # os.system(command)

def read_request_config_file():
    pb_list = []
    with open('request_config.json', 'r') as load_f:
        pb_list = json.load(load_f)
    path = './psl-be-protocol/'
    dir_list : List[str] = ['database','partystar','room']
    res_files = []
    for sub_path in dir_list:
        files = os.listdir(path + sub_path)
        for deal_file in pb_list:
            for file in files:
                res_list = re.findall(r'(.*).proto',file)
                if len(res_list) > 0:
                    if deal_file == file:
                     res_files.append(path + sub_path + '/' + file)
    for file_path in res_files:
            print(file_path)
            command ="cp "+file_path + " ./new"
            os.system(command)
            # executepotro(file_path, "PSNetworkSet")
    return res_files


def main():
    print(os.getcwd())
    now_path = os.getcwd()
    new_path = now_path + '/psl-be-protocol'
    os.chdir(new_path)

    os.system("git pull --force origin master:master")
    print('更新pb中')
    os.chdir(now_path)
    read_request_config_file()

if __name__ == '__main__':
    main()
